package com.nbufe.chain;

/**
 * @Author Zan
 * @Create 2024/6/17 8:15
 * @ClassName: Handler
 * @Description : TODO 请用一句话描述该类的功能
 */
public abstract class Handler {

    public static final int NUM_ONE = 1;
    public static final int NUM_THREE = 3;
    public static final int NUM_TEM = 10;
    public static final int NUM_TWENTY = 20;
    public static final int NUM_THIRTY = 30;

    private int startNum; // 请假开始天数
    private int endNum; // 请假结束天数
    private Handler nextHandler; // 下一个领导审核

    //设置请假天数范围 上不封顶
    public Handler(int startNum) {
        this.startNum = startNum;
    }

    // 设置请假天数范围
    public Handler(int startNum, int endNum) {
        this.endNum = endNum;
        this.startNum = startNum;
    }

    // 设置上级领导
    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }

    // 处理请假条
    public void submit(LeaveRequest leave) {
        if (leave.getNum() > NUM_THIRTY) {
            System.out.println(leave.getName() + "请假" + leave.getNum() + "天," + leave.getContent() + "。");
            System.out.println("请假天数太久了，不接受");
            System.out.println("流程结束");
            return;
        }
        //如果请假天数达到该领导者的处理要求
        if (leave.getNum() >= this.startNum) {
            this.handleLeave(leave);

            //如果还有上级 并且请假天数超过了当前领导的处理范围
            if (null != this.nextHandler && leave.getNum() > endNum) {
                this.nextHandler.submit(leave); // 继续提交
            } else {
                System.out.println("流程结束");
            }
        }
    }

    //各级领导处理请假条方法
    protected abstract void handleLeave(LeaveRequest leave);
}
